package com.api.shopapi.service.impl;


import com.api.shopapi.entity.Business;
import com.api.shopapi.entity.YearData;
import com.api.shopapi.entity.dto.BusinessDTO;
import com.api.shopapi.entity.dto.BusinessDTO1;
import com.api.shopapi.mapper.BusinessMapper;
import com.api.shopapi.service.BusinessService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("BusinessServiceImplOne")
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public int insert(Business business){
        return businessMapper.insert(business);
    }

    @Override
    public int deleteByBusinessCode(String businessCode){
        return businessMapper.deleteByBusinessCode(businessCode);
    }

    @Override
    public int updateByBusinessCode(Business business){
        return businessMapper.updateByBusinessCode(business);
    }

    @Override
    public Business getByBusinessCode(String businessCode){
        return businessMapper.getByBusinessCode(businessCode);
    }

    @Override
    public Business getByUserCode(String userCode){
        return businessMapper.getByUserCode(userCode);
    }


    @Override
    public List<Business> getList(){
        return businessMapper.getList();
    }

    @Override
    public List<BusinessDTO> getListBusinessDTOByGovernmentCode(String governmentCode){
        return businessMapper.getListBusinessDTOByGovernmentCode(governmentCode);
    }

    @Override
    public PageInfo<Business> getPageInfo(int pageNum, int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<Business> listBusiness = businessMapper.getList();
        PageInfo<Business> pageInfo = new PageInfo<Business>(listBusiness);
        return pageInfo;
    }

    @Override
    public PageInfo<BusinessDTO> getPageInfoBusinessDTO(int pageNum, int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<BusinessDTO> listBusinessDTO = businessMapper.getListBusinessDTO();
        PageInfo<BusinessDTO> pageInfo = new PageInfo<BusinessDTO>(listBusinessDTO);
        return pageInfo;
    }

    @Override
    public PageInfo<BusinessDTO> getPageInfoBusinessDTOByGovernmentCode(int pageNum, int pageSize,
                                                                        String governmentCode){
        PageHelper.startPage(pageNum, pageSize);
        List<BusinessDTO> listBusinessDTO = businessMapper.getListBusinessDTOByGovernmentCode(governmentCode);
        PageInfo<BusinessDTO> pageInfo = new PageInfo<BusinessDTO>(listBusinessDTO);
        return pageInfo;
    }

    @Override
    public BusinessDTO1 businessOrderStatistics(String businessCode, String startTime, String endTime) {
        return businessMapper.businessOrderStatistics(businessCode, startTime, endTime);
    }

    @Override
    public PageInfo<BusinessDTO1> getPageForGov(int pageIndex, int pageSize, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        return new PageInfo<>(businessMapper.getPageForGov(governmentCode));
    }

    @Override
    public YearData getBusinessYearData(String businessCode) {
        return businessMapper.getBusinessYearData(businessCode);
    }

}
